package ac.svn.accesscontrol.ui.window;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.GridLayout;
import java.awt.Toolkit;

import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextField;
import javax.swing.JTextPane;
import javax.swing.LayoutStyle.ComponentPlacement;
import javax.swing.ListSelectionModel;
import javax.swing.border.LineBorder;
import javax.swing.border.TitledBorder;

import ac.svn.accesscontrol.store.IResources;
import ac.svn.accesscontrol.utils.Utility;

public class IdentifierChangerDialog extends JDialog 
{
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private JCheckBox groupCheckBox;
	private JCheckBox userCheckBox;
	private JCheckBox locationCheckBox;
	private JLabel lblItemIdentifier;
	private JTextField itemIdTxt;
	private JTextPane progressTextArea;
	private JTextPane detialsTextArea;
	private JList itemList;
	private JButton applyButton;
	private JTextField searchField;
	public IdentifierChangerDialog() 
	{
		super();
		setModal(true);
		setTitle("Identifier Change Dialog");
		setSize(800,600);
		setOnCenterOfScreen();
		
		JScrollPane scrollPane = new JScrollPane();
		
		JLabel lblSelectSvnItems = new JLabel("Select SVN Items");
		
		lblItemIdentifier = new JLabel("Item Identifier");
		
		itemIdTxt = new JTextField();
		itemIdTxt.setColumns(10);
		
		JScrollPane detailsScrollPane = new JScrollPane();
		detailsScrollPane.setBorder(new TitledBorder(new LineBorder(new Color(192, 192, 192)), "Item Details", TitledBorder.LEADING, TitledBorder.TOP, null, null));
		
		applyButton = new JButton("Apply");
		applyButton.setMnemonic('A');
		
		JScrollPane scrollPaneProgress = new JScrollPane();
		scrollPaneProgress.setBorder(new TitledBorder(new LineBorder(new Color(192, 192, 192)), "Progress", TitledBorder.LEADING, TitledBorder.TOP, null, null));
		GroupLayout groupLayout = new GroupLayout(getContentPane());
		groupLayout.setHorizontalGroup(
			groupLayout.createParallelGroup(Alignment.LEADING)
				.addGroup(groupLayout.createSequentialGroup()
					.addContainerGap()
					.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
						.addGroup(groupLayout.createSequentialGroup()
							.addComponent(scrollPane, GroupLayout.PREFERRED_SIZE, 204, GroupLayout.PREFERRED_SIZE)
							.addPreferredGap(ComponentPlacement.UNRELATED)
							.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
								.addGroup(groupLayout.createSequentialGroup()
									.addComponent(lblItemIdentifier)
									.addPreferredGap(ComponentPlacement.RELATED)
									.addComponent(itemIdTxt, GroupLayout.DEFAULT_SIZE, 412, Short.MAX_VALUE)
									.addPreferredGap(ComponentPlacement.RELATED)
									.addComponent(applyButton))
								.addComponent(detailsScrollPane, GroupLayout.DEFAULT_SIZE, 550, Short.MAX_VALUE)
								.addComponent(scrollPaneProgress, Alignment.TRAILING, GroupLayout.DEFAULT_SIZE, 550, Short.MAX_VALUE)))
						.addComponent(lblSelectSvnItems))
					.addContainerGap())
		);
		groupLayout.setVerticalGroup(
			groupLayout.createParallelGroup(Alignment.LEADING)
				.addGroup(groupLayout.createSequentialGroup()
					.addContainerGap()
					.addComponent(lblSelectSvnItems)
					.addPreferredGap(ComponentPlacement.RELATED)
					.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
						.addGroup(groupLayout.createSequentialGroup()
							.addGroup(groupLayout.createParallelGroup(Alignment.BASELINE)
								.addComponent(applyButton)
								.addComponent(lblItemIdentifier)
								.addComponent(itemIdTxt, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
							.addPreferredGap(ComponentPlacement.UNRELATED)
							.addComponent(detailsScrollPane, GroupLayout.PREFERRED_SIZE, 111, GroupLayout.PREFERRED_SIZE)
							.addGap(8)
							.addComponent(scrollPaneProgress, GroupLayout.DEFAULT_SIZE, 367, Short.MAX_VALUE))
						.addComponent(scrollPane, GroupLayout.DEFAULT_SIZE, 520, Short.MAX_VALUE))
					.addContainerGap())
		);
		
		progressTextArea = new JTextPane();
		scrollPaneProgress.setViewportView(progressTextArea);
		
		detialsTextArea = new JTextPane();
		detailsScrollPane.setViewportView(detialsTextArea);
		
		JPanel panel = new JPanel();
		scrollPane.setColumnHeaderView(panel);
		panel.setLayout(new GridLayout(4, 1, 0, 1));
		
		userCheckBox = new JCheckBox("User");
		userCheckBox.setSelected(true);
		panel.add(userCheckBox);
		
		groupCheckBox = new JCheckBox("Group");
		groupCheckBox.setSelected(true);
		panel.add(groupCheckBox);
		
		locationCheckBox = new JCheckBox("Location");
		locationCheckBox.setSelected(true);
		panel.add(locationCheckBox);
		
		JPanel searchPanel = new JPanel();
		panel.add(searchPanel);
		searchPanel.setLayout(new BorderLayout(5, 0));
		
		JLabel lblNewLabel = new JLabel("F3");
		lblNewLabel.setIcon(Utility.getImageIcon(IResources.LOC_ICN_SEARCH));
		searchPanel.add(lblNewLabel, BorderLayout.WEST);
		
		searchField = new JTextField();
		searchPanel.add(searchField, BorderLayout.CENTER);
		searchField.setColumns(10);
		
		itemList = new JList();
		itemList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
		scrollPane.setViewportView(itemList);
		getContentPane().setLayout(groupLayout);
	}
	/**
	 * @return the groupCheckBox
	 */
	public JCheckBox getGroupCheckBox() {
		return groupCheckBox;
	}
	/**
	 * @return the userCheckBox
	 */
	public JCheckBox getUserCheckBox() {
		return userCheckBox;
	}
	/**
	 * @return the locationCheckBox
	 */
	public JCheckBox getLocationCheckBox() {
		return locationCheckBox;
	}
	/**
	 * @return the lblItemIdentifier
	 */
	public JLabel getLblItemIdentifier() {
		return lblItemIdentifier;
	}
	/**
	 * @return the itemIdTxt
	 */
	public JTextField getItemIdTxt() {
		return itemIdTxt;
	}
	/**
	 * @return the progressTextArea
	 */
	public JTextPane getProgressTextArea() {
		return progressTextArea;
	}
	/**
	 * @return the detialsTextArea
	 */
	public JTextPane getDetialsTextArea() {
		return detialsTextArea;
	}
	/**
	 * @return the itemList
	 */
	public JList getItemList() {
		return itemList;
	}
	/**
	 * @return the applyButton
	 */
	public JButton getApplyButton() {
		return applyButton;
	}
	/**
	 * @return the searchField
	 */
	public JTextField getSearchField() {
		return searchField;
	}

	public void addProgressText(String text, boolean clearFirst)
	{
		if(clearFirst)
		{
			progressTextArea.setText("");
		}
		
		progressTextArea.setText(progressTextArea.getText() + "\n" + text);
	}
	
	private void setOnCenterOfScreen()
	{
		Dimension scrSize = Toolkit.getDefaultToolkit().getScreenSize();
		setLocation(((int)scrSize.getWidth()/2 - getWidth()/2),((int)scrSize.getHeight()/2 - getHeight()/2));
	}
	
	
}
